<template>
    <!-- 
    <b-modal ref="my-modal" hide-footer title="Using Component Methods">
     <div class="d-block text-center">
       <h3>Hello From My Modal!</h3>
     </div>
     <b-button class="mt-3" variant="outline-danger" block @click="hideModal">Close Me</b-button>
     <b-button class="mt-2" variant="outline-warning" block @click="toggleModal">Toggle Me</b-button>
   </b-modal> 
    -->
    <!--
        body-class="modalStyle" 表示样式
        size="lg" 表示模态窗口大小 xl,lg,sm,full
        hide-footer 表示隐藏底部按钮
        hide-header 表示隐藏头部内容
        no-close-on-backdrop 表示鼠标点击背景不可关闭
        hide-header-close 表示隐藏头部关闭按钮
        centered 居中
        ok-title=“确定” 
        cancel-title=取消
        @ok="handleOk" 
        @cancel="handleCancel"
        scrollable 滚动条
        hide-backdrop 隐藏背景
        wrapClassName="ant-modal-cust-warp" 
        style="top:5%;height: 85%;overflow-y: hidden" 样式
    -->
    <b-modal ref="my-modal" size="lg" title="流程监听器详情" hide-footer scrollable no-close-on-backdrop>
        <div class="d-block text-center">
            <!--begin::div-->
            <div class="m-form m-form--fit m-form--label-align-left m-form--group-seperator-dashed">
                <div class="m-portlet__body">
                    <div class="form-group m-form__group row">
                        <label class="col-lg-2 col-form-label">名&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称</label>
                        <div class="col-lg-4">
                            <input class="form-control" type="text" maxlength="100" disabled v-model="lcListenerForm.name" placeholder="请输入">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-md-2 col-form-label">分&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;类</label>
                        <div class="col-md-3">
                            <select class="form-control" disabled v-model="lcListenerForm.categories" >
                                <option value="">请选择</option>
                                <option value="100">任务监听</option>
                                <option value="200">执行监听</option>
                                <option value="300">基于连线执行监听</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-md-2 col-form-label">类&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;型</label>
                        <div class="col-md-3">
                            <select class="form-control" disabled v-model="lcListenerForm.type">
                                <option value="">请选择</option>
                                <option value="javaclass">Java类</option>
                                <option value="express">表达式</option>
                                <option value="delegateExpression">委托表达式</option>
                                <option value="ScriptExecutionListener">脚本执行监听器</option>
                                <option value="ScriptTaskListener">脚本任务监听器</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-md-2 col-form-label">事&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;件</label>
                        <div class="col-md-3">
                            <select class="form-control" disabled style="width: 150px;" v-model="lcListenerForm.event">
                                <option value="">请选择</option>
                                <option v-for="item in eventList" 
                                    :key="item.key" 
                                    :label="item.value"
                                    :value="item.key">
                                </option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-md-2 col-form-label">事&nbsp;&nbsp;件&nbsp;值</label>
                        <div class="col-md-3">
                            <input class="form-control" type="text" disabled maxlength="255" v-model="lcListenerForm.listenerVal" placeholder="请输入">
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-md-2 col-form-label">产&nbsp;品&nbsp;&nbsp;线</label>
                        <div class="col-md-3">
                            <select class="form-control" style="width: 150px;" disabled v-model="lcListenerForm.lcProductId">
                                <option value="">请选择</option>
                                <option v-for="item in productList" 
                                    :key="item.id" 
                                    :label="item.name"
                                    :value="item.id">
                                </option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-md-2 col-form-label">产&nbsp;品&nbsp;&nbsp;组</label>
                        <div class="col-md-3">
                            <select class="form-control" style="width: 150px;" disabled v-model="lcListenerForm.lcGroupId">
                                <option value="">请选择</option>
                                <option v-for="item in groupList" 
                                    :key="item.id" 
                                    :label="item.name"
                                    :value="item.id">
                                </option>
                            </select>
                        </div>
                    </div>
                    <div class="form-group m-form__group row">
                        <label class="col-md-2 col-form-label">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注</label>
                        <div class="col-md-6">
                            <textarea class="form-control" maxlength="255" disabled v-model="lcListenerForm.remark" placeholder="请输入"></textarea>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <template slot="modal-footer">
            <!--自定义按钮-->
        </template>
    </b-modal>        
</template>
<script>
import apiUtil from "@/core/util/apiUtil.js"; 
import { handleNotify,handleAlert,handleConfirm,showWating,closeWating} from "@/core/util/jehcUtil.js";
export default {
    data(){
        return {   
            eventList:[],
            productList:[],
            groupList:[],
            lcListenerForm:{
                name: "",
                categories:"",
                type:"",
                event:"",
                event_:"",
                listenerVal:"",
                lcProductId:"",
                lcProductId_:"",
                lcGroupId:"",
                remark:"",
            }
        }
    },
    components: {
        
    },
    watch: {        
        "lcListenerForm.categories":{//监听字段变化
            handler:function(newVal,old){
                this.lcListenerForm.event = "";
                this.lcListenerForm.event = "";                
                if(newVal == "" || newVal == undefined || newVal == null){
                }else{
                    this.eventList = [];
                    if(newVal == 100){
                        this.eventList.push({"key":"create","value":"create"});
                        this.eventList.push({"key":"assignment","value":"assignment"});
                        this.eventList.push({"key":"complete","value":"complete"});
                        this.eventList.push({"key":"all","value":"all"});
                    }
                    if(newVal == 200){
                        this.eventList.push({"key":"start","value":"start"});
                        this.eventList.push({"key":"end","value":"end"});
                    }
                    if(newVal == 300){
                        this.eventList.push({"key":"start","value":"start"});
                        this.eventList.push({"key":"end","value":"end"});
                        this.eventList.push({"key":"take","value":"take"});
                    }
                }
                if(this.lcListenerForm.event_ == "" || this.lcListenerForm.event_ == undefined || this.lcListenerForm.event_ == null){
                    
                }else{
                    this.lcListenerForm.event = this.lcListenerForm.event_;
                    this.lcListenerForm.event_ = "";
                }
            }
        },
        "lcListenerForm.lcProductId":{//监听字段变化
            handler:function(newVal,old){
                this.lcListenerForm.lcGroupId = "";
                this.lcListenerForm.lcGroupId_ = "";                
                if(newVal == "" || newVal == undefined || newVal == null){
                    this.groupList=[];
                }else{
                    this.initGroupList(newVal)
                }
                if(this.lcListenerForm.lcGroupId_ == "" || this.lcListenerForm.lcGroupId_ == undefined || this.lcListenerForm.lcGroupId_ == null){
                    
                }else{
                    this.lcListenerForm.lcGroupId = this.lcListenerForm.lcGroupId_;
                    this.lcListenerForm.lcGroupId_ = "";
                }
            }
        },
    },
    mounted() {
        
    },
    methods: {        
        showModal(id) {
            this.restForm();
            this.$refs['my-modal'].show();
            this.initProductList();
            this.getDetail(id)
        },
        hideModal() {
            this.$refs['my-modal'].hide()
        },
        toggleModal() {
            // 当模态已隐藏时，我们传递要返回焦点的按钮的ID
            this.$refs['my-modal'].toggle('#toggle-btn')
        },
        restForm(){
            //重置
            Object.assign(this.$data.lcListenerForm, this.$options.data().lcListenerForm);
        },
        initProductList(){
            let params = {};
            apiUtil.post(process.env.VUE_APP_WORKFLOW_API + "/lcProduct/find", params).then(({ data }) => {
                this.productList = data.data;
            });
        },
        initGroupList(id){
            let params = {};
            apiUtil.query(process.env.VUE_APP_WORKFLOW_API + "/lcGroup/find/"+id, params).then(({ data }) => {
                this.groupList = data.data;
            });
        },
        getDetail(id){
            apiUtil.get(process.env.VUE_APP_WORKFLOW_API+"/lcListener/get/"+id).then(({ data }) => {
                this.lcListenerForm = data.data;
                this.initGroupList(this.lcListenerForm.lcProductId);
                this.lcListenerForm.lcGroupId_ = data.data.lcGroupId;
                this.lcListenerForm.event_ = data.data.event;
            });
        },
   }
}
</script>